Vue3中[Vue warn]: Property “XXX“ was accessed during render but is not defined on instance.警告

您所在的位置:网站首页 vue 3d模型 标签 Vue3中[Vue warn]: Property “XXX“ was accessed during render but is not defined on instance.警告

Vue3中[Vue warn]: Property “XXX“ was accessed during render but is not defined on instance.警告

2023-06-04 01:27| 来源: 网络整理| 查看: 265

Vue3中[Vue warn]: Property “XXX” was accessed during render but is not defined on instance.警告,并且组件内容无法正常显示,具体如下所示 在这里插入图片描述 vue中的代码

{{ title }} import { ref } from 'vue'; const title = ref('这个是一个标题。。。。。。。。。。。。。。。。。')

这是运行的代码是一片空白的,根本就不能显示这个vue组件的内容,之所以出现这个错误的原因,是因为在vue3中使用组合式API的时候, script标签中没有加setup。script标签中没有加setup, script标签中没有加setup,script标签中没有加setup, 这里应该是

// 就是这个,在script中加上setup就行了

如果想用ts的话,就在script标签中加上lang=“ts”,这个vue3项目使用vite创建时最好是选择typescript。而不是创建js的项目

完整的代码如下

{{ title }} import { ref } from 'vue'; const title = ref('这个是一个标题。。。。。。。。。。。。。。。。。')

或者

{{ title }} import { ref } from 'vue'; const title = ref('这个是一个标题。。。。。。。。。。。。。。。。。')

正常的运行结果如下,就可以正常显示组件的内容了 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3